/**
 * 
 */
package view;

import java.awt.Rectangle;

import model.ImageLoader;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

/**
 * @author Vincent Genecand
 *
 */
public class LetterDisplay extends Spielelement {

	private Texture[] frame;
	private String path;
	private boolean visible = false;
	private static int count = 0;

	/**
	 * @param posX
	 * @param posY
	 */
	public LetterDisplay(int posX, int posY, char letter) {
		super(posX, posY);
		this.position = new Rectangle(posX, posY, 8, 8);
		this.frame = new Texture[1];
		this.path = "gfx/letters/" + letter + ".png";
		count++;
	}
	
	@Override
	public void loadImage(ImageLoader loader){
		super.loadImage(loader);
		frame[0] = loadImageIntoQuad(path);
	}
	
	@Override
	public void renderQuad(int dX, int dY) {
		if(visible){
			int x = position.x;
			int y = position.y;
			

			frame[0].bind();

			
			/** Nullpunkt ist oben links!! */
			GL11.glBegin(GL11.GL_QUADS);
				/** Eckpunkt rechts unten */
				GL11.glTexCoord2f(1,1);
				GL11.glVertex2f(x + position.width, y);
				/** Eckpunkt unten links */
				GL11.glTexCoord2f(0,1);
				GL11.glVertex2f(x, y);
				/** Eckpunkt oben links */
				GL11.glTexCoord2f(0,0);
				GL11.glVertex2f(x, y + position.height);
				/** Eckpunkt oben rechts */
				GL11.glTexCoord2f(1,0);
				GL11.glVertex2f(x + position.width, y + position.height);
			GL11.glEnd();
		}
	}

	/**
	 * @param visible the visible to set
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
		count--;
	}
	
	public boolean allFound() {
		return (count == 0);
	}

}
